package com.ruoyi.system.service.impl;


import com.ruoyi.system.domain.dto.TrainingMealStatisticDTO;
import com.ruoyi.system.mapper.TrainingMealStatisticMapper;
import com.ruoyi.system.service.ITrainingMealStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainingMealStatisticServiceImpl implements ITrainingMealStatisticService {

    @Autowired
    private TrainingMealStatisticMapper trainingMealStatisticMapper;

    @Override
    public List<TrainingMealStatisticDTO> getTrainingMealStatisticsByMonth(String month) {
        // 验证月份格式
        if (!isValidMonthFormat(month)) {
            throw new IllegalArgumentException("月份格式不正确，应为yyyy-mm格式");
        }
        return trainingMealStatisticMapper.selectTrainingMealStatisticsByMonth(month);
    }

    private boolean isValidMonthFormat(String month) {
        return month != null && month.matches("\\d{4}-\\d{2}");
    }
}